<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加团购商品</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/temp/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/temp/css/frame.css">

    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>           
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>添加团购商品</legend>
</fieldset>

<form class="layui-form layui-form-pane" action="" lay-filter="example" style="padding: 20px">
    <div class="layui-form-item">
        <label class="layui-form-label">所属店铺</label>
        <div class="layui-input-inline" style="width: 40%">
            <select name="admin_id" lay-filter="admin_id">
                <option value="">-- 请选择店铺 --</option>
                {foreach $shop_list as $k => $v}
                <option value="{$v.id}">{$v.nickname}</option>
                {/foreach}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">团购商品</label>
        <div class="layui-input-inline" style="width: 40%">
            <select name="goods_id" id="goods_id">
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">单买价格</label>
        <div class="layui-input-inline" style="width: 40%">
            <input type="number" name="price_only" lay-verify="price_only" autocomplete="off" placeholder="请输入单买价格" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">二人团价格</label>
        <div class="layui-input-inline" style="width: 40%">
            <input type="number" name="price_sec" lay-verify="price_sec" autocomplete="off" placeholder="请输入二人团价格" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">三人团价格</label>
        <div class="layui-input-inline" style="width: 40%">
            <input type="number" name="price_thi" lay-verify="price_thi" autocomplete="off" placeholder="请输入三人团价格" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">划线价</label>
        <div class="layui-input-inline" style="width: 40%">
            <input type="number" name="price_original" lay-verify="price_original" autocomplete="off" placeholder="请输入划线价" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">销售时间</label>
        <div class="layui-input-inline" style="width: 40%">
            <input type="number" name="group_time" lay-verify="group_time" autocomplete="off" placeholder="请输入销售时间" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">
            <span style="color: red">*</span> 单位：天
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">拼团时间</label>
        <div class="layui-input-inline" style="width: 40%">
            <input type="number" name="wait_time" lay-verify="wait_time" autocomplete="off" placeholder="请输入拼团时间" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">
            <span style="color: red">*</span> 单位：天
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit">立即提交</button>
            <a href="javascript:history.back(-1)" class="layui-btn layui-btn-primary">返回</a>
        </div>
    </div>
</form>
          
<script src="/static/temp/layui/layui.js" charset="utf-8"></script>

<script>
    layui.use(['form', 'layedit'], function(){
        var form = layui.form;

        // 监听提交
        form.on('submit(submit)', function(data){
            $.post('{:url("Goods/group_add_data")}', data.field, function(res){
                if(res.code == 0){
                    layer.msg(res.msg, {icon: 1});
                    setTimeout(() => {
                        // window.location.href = "{:url('Goods/goods_group_list')}";
                        history.back(-1);
                    }, 1000);
                }else{
                    layer.msg(res.msg, {icon: 2});
                }
            })

            return false;
        });

        // 下拉框事件
        form.on('select(admin_id)', function(data){
            // console.log(data.elem); //得到select原始DOM对象
            // console.log(data.value); //得到被选中的值
            // console.log(data.othis); //得到美化后的DOM对象

            $.ajax({
                type: 'post',
                url: '{:url("Goods/getAdminGoodsList")}',
                data: {admin_id:data.value},
                dataType:'json',
                success:function(res){
                    if(res.code == 0){
                        $("#goods_id").html('<option value="">-- 请选择团购商品 --</option>');

                        res.data.forEach(val => {
                            $("#goods_id").append(`<option value="${val.id}">${val.title}</option>`)
                        })

                        form.render()
                    }else{
                        layer.msg('数据错误', {icon: 2});
                    }
                },error:function(msg){
                    layer.msg('数据错误', {icon: 2});
                }
            })
        });
    });
</script>
</body>
</html>